'use strict';

var obj = {
    name: 'bob',
    school: 'No.1 middle school',
    address: 'xueyuan road'
};

var _ = require('./underscore');

//map函数作用于obj，function (value, key)，第一个参数接收value，第二个参数接收key：
var str = _.map(obj,(y,x) => x + ' : ' + y);
console.log(str);

//mapObject()就是针对object的map版本
var str1 = _.mapObject(obj,(y,x) => x + ' : ' + y);
//console.log(str1);

var r = _.chain([1, 4, 9, 16, 25])
         .map(Math.sqrt)
         .filter(x => x % 2 === 1)
         .value();

console.log(r);

function Student(name, age) {
    this.name = name;
    this.age = age;
}

var xiaoming = new Student('小明', 20);

//返回一个object自身所有的key，但不包含从原型链继承下来的
_.keys(xiaoming); // ['name', 'age']

function Student(name, age) {
    this.name = name;
    this.age = age;
}
Student.prototype.school = 'No.1 Middle School';
var xiaoming = new Student('小明', 20);

_.allKeys(xiaoming); // ['name', 'age', 'school']

_.values(obj); // ['小明', 20]

var obj = { a: 1, b: 2, c: 3 };
// 注意传入的函数签名，value在前，key在后:
var c = _.mapObject(obj, (v, k) => 100 + v); // { a: 101, b: 102, c: 103 }
console.log(c);

var obj = {
    Adam: 90,
    Lisa: 85,
    Bart: 59
};
_.invert(obj); // { '59': 'Bart', '85': 'Lisa', '90': 'Adam' }

var arr = ['Apple', 'orange', 'banana', 'ORANGE', 'apple', 'PEAR'];

var result = _.uniq(arr, false, function(value){
    return value.toLowerCase();
});

console.log(result);

